package util;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.Button;

public class DatePickerFragment extends DialogFragment {
	private Calendar mDate;
	OnDateSetListener mDateSetListener;
	
	public DatePickerFragment() { }
	
	public void configureDatePicker(OnDateSetListener l, Calendar c) {
		mDateSetListener = l;
		mDate = c;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current date as the default date in the picker
		int year = mDate.get(Calendar.YEAR);
		int month = mDate.get(Calendar.MONTH);
		int day = mDate.get(Calendar.DAY_OF_MONTH);

		// Create a new instance of DatePickerDialog and return it
		return new DatePickerDialog(getActivity(), mDateSetListener, year, month, day);
	}
	
	public void updateDateOfBirthButtonText(Button datePickerButton, Calendar c) {
		datePickerButton.setText(String.format("%02d-%02d-%04d",
				c.get(Calendar.MONTH) + 1,
				c.get(Calendar.DAY_OF_MONTH),
				c.get(Calendar.YEAR)));
	}
	
}
